<?php
/**
 * DMFramework
 * 
 * @license Copyright 2012 Dillen Meijboom under the Apache license version 2.0 (http://apache.org/licenses/LICENSE-2.0)
 * @author Dillen Meijboom <info@dillenm.nl>
 * @url http://dmframework.nl
 */

/**
 * The form base class can be used to create forms you can re-use later.
 * Of course you can modify them in the controllers but this can be pretty handy,
 * since it saves a lot of (already written) code.
 * 
 * @license Copyright 2012 Dillen Meijboom under the Apache license version 2.0 (http://apache.org/licenses/LICENSE-2.0)
 * @author Dillen Meijboom <info@dillenm.nl>
 * @package System.Core.Application
 */
abstract class Dmf_Application_Form extends Dmf_Form
{
    /**
     * The name of the form
     * 
     * @var string 
     */
    protected $_name;
    
    /**
     * Constructor
     * 
     * @param array $exclude
     * @param boolean $reversed 
     */
    public function __construct( $exclude = array(), $reversed = true )
    {
        parent::__construct( $this->_name );
        
        $this->configure();
        
        foreach( $this->_elements as &$element )
        {
            if ( ( in_array( $element->getAttr( 'name' ), $exclude ) ) === $reversed )
            {
                $element = null;
            }
        }
        
        $this->_elements = array_values( array_filter( $this->_elements ) );
    }
    
    /**
     * Create the form 
     */
    abstract function configure();
}